﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel.Channels;
using System.Text;
using System.Xml;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;

namespace PowerBooking.RSE.Domain.Behaviors
{
    public class FaultBodyWriter : BodyWriter
    {
        private object FaultDetails;
        private XmlObjectSerializer Serializer;

        public FaultBodyWriter(object faultDetails, bool isJson)
            : base(true)
        {
            FaultDetails = faultDetails;
            var type = faultDetails.GetType();
            if (isJson)
                Serializer = new DataContractJsonSerializer(type);
            else
                Serializer = new DataContractSerializer(type);
        }

        protected override void OnWriteBodyContents(XmlDictionaryWriter writer)
        {
            Serializer.WriteObject(writer, FaultDetails);
        }
    }
}
